#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
long long t,n,m,a,b,c,l,r,ans;
long long ksm(long long i,long long j)
{
	long long ans1=1;
	while(j)
	{
		if(j%2==1) ans1*=i;
		i*=i;
		j/=2;
	}
	return ans1;
}
int main()
{
	freopen("alien.in","r",stdin);
	freopen("alien.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>a>>b>>c;
		ans=0;
		for(int i=1;i<=a;++i)
			for(int j=1;j<=b;++j)
				for(int z=1;z<=c;++z)
					if(ksm(j,i)==ksm(i,z))
						++ans;
		cout<<ans<<'\n';
	}
	return 0;
}
